package com.hisan.freeride.home.activity;
import android.os.Bundle;
import com.hisan.freeride.R;
import com.hisan.freeride.common.base.AppConfig;
import com.hisan.freeride.common.base.BaseActivity;
import com.hisan.freeride.common.callback.DialogCallback;
import com.hisan.freeride.common.state.EmptyState;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.databinding.TidingsDetailsBinding;
import com.hisan.freeride.home.model.DMessage;
import com.lzy.okgo.OkGo;



/**
 * 促销消息详情
 * Created by Administrator on 2017/4/6.
 */

public class Message_DetailsActivtity extends BaseActivity<TidingsDetailsBinding> {
    private  int id;
    private int type=1;
    @Override
    protected int getLayoutId() {
        return R.layout.tidings_details;
    }

    @Override
    protected void initView() {
        mBinding.setStateModel(mStateModel);
        Bundle bundle=getIntent().getExtras();
        if (!CollectionUtils.isNullOrEmpty(bundle)){
            id=bundle.getInt("id");
            type=bundle.getInt("type");
        }
        mBinding.setStateModel(mStateModel);
    }

    @Override
    protected void initEvent() {
        mBinding.topBack.setOnClickListener(v -> finishActivity(true));
    }

    @Override
    protected void loadData(boolean isRefresh) {


        OkGo.<DMessage>get(AppConfig.ArticleDetail)
                .tag(this)
                .params("id",id)
                .execute(new DialogCallback<DMessage>(this){
                    @Override
                    public void onSuccess(com.lzy.okgo.model.Response<DMessage> response) {
                        super.onSuccess(response);
                        if (!CollectionUtils.isNullOrEmpty(response.body())){
                            mStateModel.setEmptyState(EmptyState.NORMAL);
                            mBinding.mName.setText(response.body().getTitle());
                            mBinding.mData.setText(response.body().getCreate_time());
                            if (type==1)
                            mBinding.titlename.setText("活动详情");
                            mBinding.trainingWebview.SetData(response.body().getContent());
                        }else {
                            mStateModel.setEmptyState(EmptyState.EMPTY);
                        }
                    }

                    @Override
                    public void onError(com.lzy.okgo.model.Response<DMessage> response) {
                        super.onError(response);
                        showErrorView(response.code());
                    }
                });
    }



}
